﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace CommonFactory
{
    public abstract class CommonFactory<TTarget,TData> : ICommonFactory<TTarget, TData> where TTarget : ICommonProduct where TData:ICommonProductData
    {
        protected List<ICommonBuilder> commonBuilders;

        public TData Data
        {
            get;protected set;
        }

        public CommonFactory(TData data)
        {
            Data = data;
        }

        public virtual TTarget CreateProduct()
        {
            GameObject go = Resources.Load<GameObject>(Data.ResPath);

            TTarget target = MonoBehaviour.Instantiate(go).GetComponent<TTarget>();
            for (int i = 0; i < commonBuilders.Count; i++)
            {
                commonBuilders[i].Builder(target);
            }
            return target;
        }
        
    }
}
